import i18n, { routeI18n } from '@/locale'
import type { Router } from 'vue-router';

const baseTitle = import.meta.env.VITE_APP_TITLE

// 标题
export function createPageTitleGuard(router: Router) {
  router.afterEach((to) => {
    const pageTitle = routeI18n(to, i18n.global.locale.value)
    if (pageTitle) {
      document.title = `${baseTitle} - ${pageTitle}`
    } else {
      document.title = baseTitle
    }
  })
}
